import { get, post } from "jquery"
import * as interfaces from './Interfaces.json'

export const asynclogin = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.login, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const session = function () {
    return new Promise((resolve, reject) => {
        get(interfaces.online).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const allUser = function () {
    return new Promise((resolve, reject) => {
        get(interfaces.getAllUser).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const getallcourse = function () {
    return new Promise((resolve, reject) => {
        get(interfaces.AllCourse).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}



export const packagekey = function () {
    return new Promise((resolve, reject) => {
        get(interfaces).then(response => {
            if (response.error == 0) {
                resolve(response.packagekey)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 通过cid 获取course 和courseliseeion 的方法
export const asyncgetCourseAndLessionsByCourseID = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getCourseAndLessionsByCourseID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取上传权限
export const asyncuploadAccess = function () {
    return new Promise((resolve, reject) => {
        get(interfaces.uploadAccess).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 上传course
export const asyncuploadCourse = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.uploadCourse, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 上传course
export const asyncupdateCourse = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.updateCourse, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除course
export const asyncdeleteCourse = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteCourse, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加lession
export const asyncuploadLession = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.uploadLession, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 更新lession
export const asyncupdateLession = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteLession, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}
// 删除lession
export const asyncdeleteLession = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteLession, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(response.msg)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加代理商
export const asyncnewAgent = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.newAgent, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 添加package
export const asyncnewPackege  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.newPackege, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加AgentKey
export const asyncaddAgentKey  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.addAgentKey, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加AgentKey
export const asyncaddPackegeKey  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.addPackegeKey, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 添加addPackege
export const asyncaddPackege  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.addPackege, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取package
export const asyncgetAllPackege  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getAllPackege, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取package
export const asyncgetCourseByPackegeID  = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getCourseByPackegeID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetUserByUser = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getUserByUser, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

export const asyncgetUserCourseInfo = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getUserCourseInfo, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 获取代理商课程包
export const asyncgetAgentCoursePak = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getAgentCoursePak, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除代理商课程包
export const asyncdeleteAgebtKeyByID = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteAgebtKeyByID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

//  删除课程包的课程
export const asyncdeletePackegeByID = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deletePackegeByID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除课程包
export const asyncdeletePackegeKeyByID = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deletePackegeKeyByID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 修改用户
export const asyncupdateUser = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.updateUser, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 删除用户
export const asyncdeleteUserByID = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteUserByID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 修改课程包
export const asyncupdatePackegeKey = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.updatePackegeKey, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}




export const asyncvideoQuestion = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.videoQuestion, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 添加视频问题
export const asyncuploadQuestion = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.uploadQuestion, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}


// 修改视屏问题
export const asyncupdateQuestion = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.updateQuestion, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 删除视频问题

export const asyncdeleteQuestion = function (data) {
    return new Promise((resolve, reject) => {
        post(interfaces.deleteQuestion, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 管理员获取视频
export const asyncgetVideoPermissionByID = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.getVideoPermissionByID, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}

// 提交答案 
export const asynccheckQuestion = function(data) {
    return new Promise((resolve, reject) => {
        post(interfaces.checkQuestion, data).then(response => {
            if (response.error == 0) {
                resolve(response.data)
            } else {
                reject(false)
            }
        }).catch(function (error) {
            reject(error)
        })
    })
}